package com.example.demo.information.repository;

import com.example.demo.information.entity.School;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author littlecar
 * @date 2020/3/11 14:15
 */
@Repository
public interface SchoolRepository  extends JpaRepository<School,Long> {

    @Query(nativeQuery = true, value = " select s.* from school s where s.name = ?1 ")
    List<School> findByName(String school_name);

    @Query(nativeQuery = true, value = " select s.* from school s where s.name like ?1 ")
    List<School> findByNameLike(String school_name);

    @Query(nativeQuery = true, value = " select s.* from school s  limit ?1,?2")
    List<School> findPageAll(int pages, Integer limit);

    @Override
    @Query(nativeQuery = true, value = " select s.* from school s ")
    List<School> findAll();

    @Query(nativeQuery = true, value = " select s.* from school s where s.name like ?1  limit ?2,?3")
    List<School> findPageByNameLike(String school_name, int pages, Integer limit);

    @Query(nativeQuery = true, value = " select count(1) from school s where s.name like ?1")
    int countByNameLike(String school_name);
}
